Skip to content

common/chat : unify and fix LFM2/LFM2.5 tool parser#24178

Merged
aldehir merged 1 commit into
ggml-org:masterfrom
tdakhran:tarek/fix/lfm2.5-tool-calling
Jun 5, 2026
Merged

common/chat : unify and fix LFM2/LFM2.5 tool parser#24178
aldehir merged 1 commit into
ggml-org:masterfrom
tdakhran:tarek/fix/lfm2.5-tool-calling

Conversation

@tdakhran
Copy link
Copy Markdown
Contributor

@tdakhran tdakhran commented Jun 5, 2026

Overview

LFM2 and LFM2.5 share the same pythonic style tool-calling format, with the only difference being that LFM2 also wraps the system tool list in <|tool_list_start|>/<|tool_list_end|>.

Two parsers are merged into common_chat_params_init_lfm2(..., tool_list_tokens) and share logic.

Also fix and extend argument parsing:

  • convert Python literals True/False/None to JSON true/false/null
  • accept JSON-cased true/false/null in argument values (parser helps the model)
  • convert single-quoted strings to JSON strings
  • handle dotted function names, e.g. Calendar.create_event

Additional information

The parser was tested against the reference implementation and recovers tool-calling capabilities across different LFM2/LFM2.5 models. Interactive HTML with comparison attached below.

image

lfm2_tool_calling_7fe2ae45a_vs_71b74a408.html

Requirements

LFM2 and LFM2.5 share the same tool-calling format with the only
difference is that LFM2 also wraps the system tool list in
<|tool_list_start|>/<|tool_list_end|>.

Merge the two parsers into common_chat_params_init_lfm2(..., tool_list_tokens).

Also fix and extend argument parsing:
* convert Python literals True/False/None to JSON true/false/null
* accept JSON-cased true/false/null in argument values
* convert single-quoted strings to JSON strings
* handle dotted function names, e.g. Calendar.create_event

// insert image here
@tdakhran tdakhran requested review from a team and pwilkin as code owners June 5, 2026 11:51
@github-actions github-actions Bot added the testing Everything test related label Jun 5, 2026
@liebedan
Copy link
Copy Markdown

liebedan commented Jun 5, 2026

I'd love to see this merged. IMHO the conversion of the literals from Python to JSON could solve problems that many people seem to have when it comes to LFM2.5 tool calling. As described in this issue over at HF.

@Dev-iL
Copy link
Copy Markdown

Dev-iL commented Jun 5, 2026

Related: #24071

Copy link
Copy Markdown
Member

@pwilkin pwilkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear everything just operates in cycles - back in the day we had a full python dict parser in the autoparser code, but we removed it because we figured nobody uses that syntax anymore... ;)

@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented Jun 5, 2026

CC @aldehir if you can do a quick review

Copy link
Copy Markdown
Contributor

@aldehir aldehir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed missing is copying the reasoning_content field to thinking as expected by the template.

Also, if the logic to accept [tool_name as a tool call without the leading tool call marker is incorrect, then I recommend removing the parsing and grammar triggers for it. Ref: #24071 (comment)

I'm fine if you want to address these in a separate PR. Otherwise, LGTM.

@tdakhran
Copy link
Copy Markdown
Contributor Author

tdakhran commented Jun 5, 2026

One thing I noticed missing is copying the reasoning_content field to thinking as expected by the template.

Also, if the logic to accept [tool_name as a tool call without the leading tool call marker is incorrect, then I recommend removing the parsing and grammar triggers for it. Ref: #24071 (comment)

I'm fine if you want to address these in a separate PR. Otherwise, LGTM.

Thank you for the feedback, @aldehir. I'll address it in a follow-up PR.

@aldehir aldehir merged commit da87e9b into ggml-org:master Jun 5, 2026
25 checks passed
@mtasic85
Copy link
Copy Markdown
Contributor

mtasic85 commented Jun 6, 2026

I was actually working on this and testing in coding agents. I will test this implementation now.

@tdakhran tdakhran deleted the tarek/fix/lfm2.5-tool-calling branch June 6, 2026 08:48
@bricss
Copy link
Copy Markdown

bricss commented Jun 6, 2026

It looks like that fix introduced a minor issue: <think></think> blocks are now visible 👁️ in the chat 💬

P.S.: The UI has been updated and now reasoning 🧠 must be enabled in chat using the 💡 button. When its disabled reasoning continues to work ⚙️ printing <think></think> blocks which is kinda a bug 🪲

@tdakhran
Copy link
Copy Markdown
Contributor Author

tdakhran commented Jun 6, 2026

It looks like that fix introduced a minor issue: <think></think> blocks are now visible 👁️ in the chat 💬

P.S.: The UI has been updated and now reasoning 🧠 must be enabled in chat using the 💡 button. When its disabled reasoning continues to work ⚙️ printing <think></think> blocks which is kinda a bug 🪲

Thanks @bricss , reproduced it. @aldehir, is it an issue with the parser you pointed, or is something else going on?

image

@tdakhran
Copy link
Copy Markdown
Contributor Author

tdakhran commented Jun 6, 2026

@bricss , https://huggingface.co/LiquidAI/LFM2.5-8B-A1B is a reasoning-only model and should be used with reasoning enabled. By design, the chat template doesn't have a toggle.

It's not a bug, it's a feature 😄 .

jimbothigpen pushed a commit to jimbothigpen/llama.cpp that referenced this pull request Jun 6, 2026
jimbothigpen pushed a commit to jimbothigpen/llama.cpp that referenced this pull request Jun 6, 2026
ggerganov pushed a commit to am17an/llama.cpp that referenced this pull request Jun 6, 2026
@tdakhran
Copy link
Copy Markdown
Contributor Author

tdakhran commented Jun 6, 2026

@aldehir , @bricss thanks again for your comments, opened a follow-up PR to address them #24234 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants